package mutsumimod.monitors;

import basemod.interfaces.OnStartBattleSubscriber;
import basemod.interfaces.PostUpdateSubscriber;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.potions.ExplosivePotion;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import mutsumimod.monsters.FakeEnemyMonster;

import java.util.LinkedList;
import java.util.Queue;

@Deprecated
public class FakeEnemyMonitor extends BaseMonitor implements OnStartBattleSubscriber, PostUpdateSubscriber {

    public static Queue<int[]> availableSlots = new LinkedList<>();

    public static final int ROW=1;
    public static final int COL=1;

    public static void initialize(){
        availableSlots.clear();
        for (int i = ROW-1; i >=0; i--) {
            for (int j = 0; j < COL; j++) {
                availableSlots.add(new int[]{i, j});
            }
        }
        //ExplosivePotion
    }

    // 直接取队首坐标（天然保证行优先顺序）
    public static int[] generateNextPosition() {
        return availableSlots.poll(); // 队列空时返回 null
    }

    // 若怪物被移除，可归还坐标到队列
    public static void returnPosition(int row, int col) {
        availableSlots.add(new int[]{row, col});
    }

    @Override
    public void receiveOnBattleStart(AbstractRoom abstractRoom) {
        initialize();
    }


    @Override
    public void receivePostUpdate() {
        if (AbstractDungeon.currMapNode==null||(AbstractDungeon.getCurrRoom()).phase != AbstractRoom.RoomPhase.COMBAT){
            return;
        }
        if(allMonsterDie()){
            for(AbstractMonster m : AbstractDungeon.getMonsters().monsters){
                if(m instanceof FakeEnemyMonster){
                    m.die();
                }
            }
        }
    }

    public boolean allMonsterDie(){
        for(AbstractMonster m:AbstractDungeon.getMonsters().monsters){
            if(!(m instanceof FakeEnemyMonster)&&!m.isDying&&!m.isDead&&!m.isEscaping){
                return false;
            }
        }
        return true;
    }
}
